package com.shay.dubbo.provider;

import com.alibaba.dubbo.rpc.RpcContext;
import com.shay.dubbo.api.ShayService;
import com.shay.dubbo.model.User;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Service
 *
 * @author shay
 * @date 2016/8/4
 */
public class ShayServiceImpl implements ShayService {
    @Override
    public int add(int a, int b) {
        return a + b;
    }

    @Override
    public String sayHello(String name) {
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
        return "Hello " + name + ", response form provider: " + RpcContext.getContext().getLocalAddress();
    }

    @Override
    public User getUser() {
        User user = new User();
        user.setId(1001L);
        user.setName("shoy");
        user.setEmail("123@123.com");
        user.setCreation(new Date());
        return user;
    }
}
